#include <stdio.h> //for printf
#include <stdlib.h> //for exit
#include "stack.h"

struct myDataNode {
    list_t node;
    char name[10];
    int age;
};
typedef struct myDataNode myNode_t;


int main() {
    myNode_t HEAD;

    init((list_t *) &HEAD);
    
    //push
    for (int i = 1; i<5; i++) {
        myNode_t *node = (myNode_t *) malloc(sizeof(myNode_t));
        sprintf(node->name, "robert_%d", i);
        node->age = 15+i;
        push((list_t*) &HEAD, (list_t*)node);
        printf("push %d into stack\n", i);
    }

    //pop

    while(!isEmpty((list_t*)&HEAD)) {
        int errorCode;
        myNode_t *x = (myNode_t *) pop((list_t*)&HEAD, &errorCode);

        if (errorCode != STACK_OK) {
            printf("pop error\n");
        } else {
            printf("pop %s from stack\n", x->name);
            free(x);
        }
    }


}